<?php
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu();
$info = pdo_get('zhtc_distribution',array('id'=>$_GPC['id']));
//自己
$level = pdo_getall('zhtc_fxlevel',array('uniacid'=>$_W['uniacid']));
$fxuser=pdo_get('zhtc_fxuser',array('fx_user'=>$info['user_id']));
//查看我的上级
$fxuser=pdo_get('zhtc_distribution',array('user_id'=>$fxuser['user_id']));
//查看上级分销商信息
// print_r($fxuser);die;
$sjuser=pdo_getall('zhtc_fxuser',array(),'fx_user');

$sjuser2=pdo_getall('zhtc_fxuser',array('user_id'=>$info['user_id']),'fx_user');
//print_R($fxuser);die;
//二维数组转一维
//
function i_array_column($input, $columnKey, $indexKey=null){
    if(!function_exists('array_column')){
        $columnKeyIsNumber  = (is_numeric($columnKey))?true:false;
        $indexKeyIsNull            = (is_null($indexKey))?true :false;
        $indexKeyIsNumber     = (is_numeric($indexKey))?true:false;
        $result                         = array();
        foreach((array)$input as $key=>$row){
            if($columnKeyIsNumber){
                $tmp= array_slice($row, $columnKey, 1);
                $tmp= (is_array($tmp) && !empty($tmp))?current($tmp):null;
            } else{
                $tmp= isset($row[$columnKey])?$row[$columnKey]:null;
            }
            if(!$indexKeyIsNull){
                if($indexKeyIsNumber){
                    $key = array_slice($row, $indexKey, 1);
                    $key = (is_array($key) && !empty($key))?current($key):null;
                    $key = is_null($key)?0:$key;
                } else{
                    $key = isset($row[$indexKey])?$row[$indexKey]:0;
                }
            }
            $result[$key] = $tmp;
        }
        return $result;
    } else{
        return array_column($input, $columnKey, $indexKey);
    }
}
$yuser=i_array_column($sjuser, 'fx_user');

foreach( $yuser as $k=>$v) {
    if($info['user_id'] == $v) unset($yuser[$k]);
}
array_push($yuser, $info['user_id']);

//print_r($yuser);die;
// echo $fxuser['user_id'];die;
//echo $info['user_id'];die;
$user=pdo_getall('zhtc_distribution',array('uniacid'=>$_W['uniacid'],'user_id !='=>$yuser,'state'=>2));
//print_r($user);die;
if(checksubmit('submit')){
   // echo $_GPC['level'];die;
    $data2['level']=$_GPC['level'];
    $data['user_id']=$_GPC['user_id'];
    $res2=pdo_update('zhtc_distribution', $data2, array('id' => $_GPC['id']));
    $res = pdo_update('zhtc_fxuser', $data, array('fx_user' => $info['user_id']));
    if($res || $res2){
        message('编辑成功',$this->createWebUrl('fxlist',array()),'success');
    } else{
        message('编辑失败','','error');
    }
}
include $this->template('web/fxinfo');